import { Component, OnInit, Input } from '@angular/core';
import {Avatar} from '../../entity/Avatar';
import {RequestReplyService} from '../../services/request-reply.service'

@Component({
  selector: 'app-avatar',
  templateUrl: './avatar.component.html',
  styleUrls: ['./avatar.component.scss']
})
export class AvatarComponent implements OnInit {
  @Input() avatar: Avatar;

  constructor( private requestService: RequestReplyService ) { }

  ngOnInit() {
    let avt = this.avatar;
    if(avt && avt.uin && !avt.url){
      console.log("loading avatar:", avt.uin)
      this.requestService.GetUser(avt.uin).subscribe((user) => {
        console.log("user:", user)
        if(user)
          avt.url = user.avatar;
      })
      
    }
  }

}
